package com.mt.mtyx.common.utils.generate.generate.config;

import com.mt.mtyx.common.utils.generate.generate.code.GenerateMethod;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;

/**
 * @author WMT
 * @Date 2023/5/26 17:27
 */
public class ServiceCodeConfig {

    /**
     * service 名称
     */
    private String serviceName;

    /**
     * service 实现类名称
     */
    private String serviceImplName;

    /**
     * service 文件格式
     */
    private String serviceFormat = "%sService";

    /**
     * serviceImpl 文件格式
     */
    private String serviceImplFormat = "%sServiceImpl";

    /**
     * service 父类
     */
    private String serviceSupperClass;

    /**
     * serviceImpl 父类
     */
    private String serviceImplSupperClass;

    /**
     * 是否开启mybatis-plus模式
     */
    private boolean enableMybatisPlus;

    /**
     * 是否注入容器
     */
    private boolean enableComponent;

    /**
     * service容器注解
     */
    private String component = "org.springframework.stereotype.Service";

    /**
     * service容器注入注解
     */
    private String autowired = "org.springframework.beans.factory.annotation.Autowired";

    /**
     * 声明式事务注解
     */
    private String transactional = "org.springframework.transaction.annotation.Transactional";

    /**
     * iService 全包名
     */
    private String iService = "com.baomidou.mybatisplus.extension.service.IService";

    /**
     * ServiceImpl全包名
     */
    private String serviceImpl = "com.baomidou.mybatisplus.extension.service.impl.ServiceImpl";

    /**
     * service 导包
     */
    private Set<String> importServicePackage;

    /**
     * serviceImpl 导包
     */
    private Set<String> importServiceImplPackage;

    /**
     * 生成的方法隐射 如果要忽略某个方法 则将他的value值设置为null即可
     */
    private final Map<String, GenerateMethod> method;

    {
        method = new LinkedHashMap<>();
        method.put("INSERT", new GenerateMethod("INSERT", null, "insert%s", null, null, null, null, null));
        method.put("DELETE", new GenerateMethod("DELETE", null, "delete%s", null, null, null, null, null));
        method.put("UPDATE", new GenerateMethod("UPDATE", null, "update%s", null, null, null, null, null));
        method.put("LIST", new GenerateMethod("LIST", null, "select%sList", null, null, null, null, null));
        method.put("ONE", new GenerateMethod("ONE", null, "selectOne%s", null, null, null, null, null));
    }

    public String getServiceName() {
        return serviceName;
    }

    public ServiceCodeConfig serviceName(String serviceName) {
        this.serviceName = serviceName;
        return this;
    }

    public String getServiceImplName() {
        return serviceImplName;
    }

    public ServiceCodeConfig serviceImplName(String serviceImplName) {
        this.serviceImplName = serviceImplName;
        return this;
    }

    public String getServiceFormat() {
        return serviceFormat;
    }

    public ServiceCodeConfig serviceFormat(String serviceFormat) {
        this.serviceFormat = serviceFormat;
        return this;
    }

    public String getServiceImplFormat() {
        return serviceImplFormat;
    }

    public ServiceCodeConfig serviceImplFormat(String serviceImplFormat) {
        this.serviceImplFormat = serviceImplFormat;
        return this;
    }

    public String getServiceSupperClass() {
        return serviceSupperClass;
    }

    public ServiceCodeConfig serviceSupperClass(String serviceSupperClass) {
        this.serviceSupperClass = serviceSupperClass;
        return this;
    }

    public String getServiceImplSupperClass() {
        return serviceImplSupperClass;
    }

    public ServiceCodeConfig serviceImplSupperClass(String serviceImplSupperClass) {
        this.serviceImplSupperClass = serviceImplSupperClass;
        return this;
    }

    public boolean isEnableMybatisPlus() {
        return enableMybatisPlus;
    }

    public ServiceCodeConfig enableMybatisPlus(boolean enableMybatisPlus) {
        this.enableMybatisPlus = enableMybatisPlus;
        return this;
    }

    public boolean isEnableComponent() {
        return enableComponent;
    }

    public ServiceCodeConfig enableComponent(boolean enableComponent) {
        this.enableComponent = enableComponent;
        return this;
    }

    public String getComponent() {
        return component;
    }

    public ServiceCodeConfig component(String component) {
        this.component = component;
        return this;
    }

    public String getiService() {
        return iService;
    }

    public ServiceCodeConfig iService(String iService) {
        this.iService = iService;
        return this;
    }

    public String getServiceImpl() {
        return serviceImpl;
    }

    public ServiceCodeConfig serviceImpl(String serviceImpl) {
        this.serviceImpl = serviceImpl;
        return this;
    }

    public Set<String> getImportServicePackage() {
        return importServicePackage;
    }

    public ServiceCodeConfig importServicePackage(Set<String> importServicePackage) {
        this.importServicePackage = importServicePackage;
        return this;
    }

    public Set<String> getImportServiceImplPackage() {
        return importServiceImplPackage;
    }

    public ServiceCodeConfig importServiceImplPackage(Set<String> importServiceImplPackage) {
        this.importServiceImplPackage = importServiceImplPackage;
        return this;
    }

    public Map<String, GenerateMethod> getMethod() {
        return method;
    }

    public ServiceCodeConfig methodMap(Consumer<Map<String, GenerateMethod>> methodMap) {
        methodMap.accept(method);
        return this;
    }

    public String getAutowired() {
        return autowired;
    }

    public ServiceCodeConfig autowired(String autowired) {
        this.autowired = autowired;
        return this;
    }

    public String getTransactional() {
        return transactional;
    }

    public ServiceCodeConfig transactional(String transactional) {
        this.transactional = transactional;
        return this;
    }
}
